// Decompiled by DJ v3.9.9.91 Copyright 2005 Atanas Neshkov  Date: 2008-6-29 11:26:58
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   LoginUtils.java

package com.creawor.hz_market.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.creawor.hz_market.bean.UserDetails;

// Referenced classes of package com.creawor.hz_market.util:
//            UserNotLoginException

public class LoginUtils
{

    public LoginUtils()
    {
    }

    public static void saveLoginUser(HttpServletRequest request, UserDetails user)
    {
        request.getSession().setAttribute("loginUser", user);
        String deptCode = user.getDeptCode();
        if(deptCode.length() > 4)
            request.getSession().setAttribute("hall", deptCode);
        else
            request.getSession().setAttribute("area", deptCode);
    }

    public static UserDetails getLoginUser(HttpServletRequest request)
        throws UserNotLoginException
    {
        HttpSession session = request.getSession(false);
        if(session == null)
            throw new UserNotLoginException();
        UserDetails result = (UserDetails)session.getAttribute("loginUser");
        if(result == null){
        	//throw new UserNotLoginException();
        	 return result;
        }
            
        else
            return result;
    }
}